package com.jiyun.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jiyun.model.xitong.Zixun;
import com.jiyun.oss.AliyunOSSUtils;
import com.jiyun.service.IZixunService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2024-09-23
 */
@RestController
@CrossOrigin
@RequestMapping("/zixun")
@Api("资讯管理")
public class ZixunController {
        @Autowired
        IZixunService zixunService;

        @Autowired
        AliyunOSSUtils aliyunOSSUtils;

        @RequestMapping("findAll")
        @ApiOperation("分页查询所有")
        public Page<Zixun> findAll(Integer pageNum, Integer pageSize, @RequestBody Zixun zixun){
                        return  zixunService.findAll(pageNum,pageSize,zixun);
        }


        @RequestMapping("upload")
        @ApiOperation("上传文件")
        public String upload(MultipartFile file) throws IOException {
                String originalFilename = file.getOriginalFilename();
                InputStream inputStream = file.getInputStream();
                String s = aliyunOSSUtils.putObject(inputStream, originalFilename);
                return s;
        }

        @RequestMapping("add")
        @ApiOperation("添加文章")
        public Integer add(@RequestBody Zixun zixun){
                        return   zixunService.add(zixun);
        }

        @RequestMapping("update")
        @ApiOperation("修改文章")
        public Integer update(@RequestBody Zixun zixun){
                return  zixunService.updates(zixun);
        }

        @RequestMapping("del")
        @ApiOperation("删除文章")
        public Integer del(Integer id){
                return  zixunService.del(id);
        }
}
